import 'package:flutter/foundation.dart';
import 'package:lib_uikit/theme/gt_theme_provider.dart';

extension GTImageExtension on String {
  /// 获取对应主题的图片资源,适用于二三级页面
  String themePath({bool maybeRTL = false}) {
    try {
      var isDark = GTThemeProvider.instance.isDark();
      var end = '.${split('.').last}';
      bool isRTL = maybeRTL ? GTThemeProvider.instance.isRTL() : false;
      var rtlPath = replaceAll(end, '${isRTL ? "_rtl" : ''}$end');
      if (isDark) {
        return rtlPath.replaceFirst("/images/", "/images_dark/");
      } else {
        return rtlPath;
      }
    } on Exception catch (e) {
      if (kDebugMode) {
        print(e);
      }
      return this;
    }
  }

  String maybeRtl() {
    try {
      var end = '.${split('.').last}';
      return replaceAll(end, '${GTThemeProvider.instance.isRTL() ? "_rtl" : ''}$end');
    } on Exception catch (e) {
      if (kDebugMode) {
        print(e);
      }
      return this;
    }
  }
}
